<?php

class Application_Model_Logs extends Zend_Db_Table_Abstract
{
    protected $_name = 'logs';
    protected $_primary = 'id';

  	public function addLog($params)
    {
         $data = array(
         	'action' => $params['action'],
            'user_id' => $params['user_id'],
         	'date_enter' => new Zend_Db_Expr('NOW()')
        );

        return $this->insert($data);
    }

    public function getLastLogByUser($user_id)
    {
        $row = $this->fetchRow(
            $this->select('action')
                 ->where($this->getAdapter()->quoteInto('user_id=?', $user_id))
                 ->order('date_enter DESC')
                 ->limit(1, 0)
        )->toArray();

        if ($row['action']) {
            return $row['action'];
        } else {
            return null;
        }
    }
}